<template>
	<view class="bgc-white">
		<view class="pt-240">
			<view class="fd-r jc-c">
				<image
					src="@/static/indexphoto/hm-icon.png"
					mode=""
					class="w-320 h-320"
				></image>
			</view>
		</view>
		<view class="px-32 pt-40">
			<button
				open-type="getPhoneNumber"
				@getphonenumber="getPhoneNumber"
				class="login-btn"
			>
				授权手机号一键登录
			</button>

			<!--  v-show="!isphonelogin" -->
			<view class="registration" @click="jumpPhoneLogin">
				使用短信验证登录
			</view>

			<view class="fd-r jc-c pt-12">
				<tm-checkbox v-model="isaccredit"></tm-checkbox>
				<view class="clontext">
					我已阅读并同意
					<text class="fs-24 c-primary" @click="HShowXY">《用户协议》</text>
					和
					<text class="fs-24 c-primary" @click="HShowZC">
						《红麦咨询隐私政策》
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';

import { useUserStore } from '@/store/user.js';
const userStore = useUserStore();


//跳转到手机号登录页面
function jumpPhoneLogin() {
	uni.navigateTo({
		url: '/pages/login/by-phone/index'
	});
}

const isaccredit = ref(true);
function getPhoneNumber(e) {
	console.log('getPhoneNumber', e);

	if (!isaccredit.value) {
		uni.showToast({
			icon: 'none',
			title: '请同意相关协议'
		});

		return;
	}
	
	userStore.HLogin(e.detail.encryptedData, e.detail.iv)
}

//打开pdf阅读
function jumpShowPFD(value) {
	uni.showLoading({
		title: '加载中'
	});
	uni.downloadFile({
		url: value,
		success: function (res) {
			var filePath = res.tempFilePath;
			uni.openDocument({
				filePath: filePath,
				showMenu: true,
				fileType: 'pdf',
				success: function () {
					uni.hideLoading();
					console.log('打开文档成功');
					uni.getFileSystemManager().removeSavedFile({
						filePath: filePath,
						success() {
							console.log('已删除文件：' + filePath);
						}
					});
				},
				fail(err) {
					console.log(err);
					uni.hideLoading();
				}
			});
		}
	});
}

function HShowXY() {
	jumpShowPFD(
		'https://fdfs.redmax.net.cn/group1/M00/00/00/wKggCWWbpGqACgd9AAPI3HbaSQ4337.pdf'
	);
}

function HShowZC() {
	jumpShowPFD(
		'https://fdfs.redmax.net.cn/group1/M00/00/00/wKggCWWbpD-Ad2uMAAR4L7QgB8E091.pdf'
	);
}

</script>

<style lang="scss" scoped>
.login-btn {
	width: 640rpx;
	height: 84rpx;
	background: #d7000f;
	border-radius: 42rpx;
	text-align: center;
	line-height: 84rpx;
	font-size: 28rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 700;
	color: rgba(255, 255, 255, 0.9);
	margin-bottom: 32rpx;
}
.registration {
	height: 84rpx;
	font-size: 28rpx;
	background: #f6f6f6;
	border-radius: 42rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 700;
	color: rgba(0, 0, 0, 0.9);
	line-height: 84rpx;
	letter-spacing: 1rpx;
	text-align: center;
}
.login-text {
	width: 100%;
	display: flex;
	justify-content: center;
	height: 40rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: rgba(0, 0, 0, 0.9);
	text-align: center;
}

.clontext {
	height: 80rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: rgba(0, 0, 0, 0.9);
	line-height: 80rpx;
}
</style>
